//  https://www.luogu.com.cn/problem/P1091

#include<iostream>
using namespace std;

const int N = 110;
int dp1[N], dp2[N], a[N];
int n;

int main()
{
    cin >> n;
    for (int i = 1;i <= n;i++) cin >> a[i];

    int ret1 = 0, ret2 = 0;
    for (int i = 1;i <= n;i++)
    {
        dp1[i] = 1;
        for (int j = 1;j < i;j++)
        {
            if (a[i] > a[j])
                dp1[i] = max(dp1[j] + 1, dp1[i]);
        }
    }

    for (int i = 1;i <= n;i++)
    {
        dp2[i] = 1;
        for (int j = 1;j < i;j++)
        {
            if (a[i] < a[j])
                dp2[i] = max(dp2[j] + 1, dp2[i]);
        }
    }
    int ret = 0;
    for (int i = 1;i <= n;i++)
    {
        ret = max(ret, dp1[i] + dp2[i] - 1);
    }

    cout << n - ret << endl;
    return 0;
}